package TestDemo;

import java.io.File;
import java.text.FieldPosition;

/**
 * 
 * @author jiayuzhu
 *
 */
public class RenameFile {
	public static void reName(String filePath,String newPath) {
		
		
		File rootFile = new File(filePath);
		if (rootFile.isDirectory()) {
			File[] files = rootFile.listFiles();
			if (files != null && files.length > 0) {
				for (int i = 0; i < files.length; i++) {
					File f = files[i];
					if (f.isDirectory()) {
						reName(f.getAbsolutePath(),newPath);
					}else if(f.getName().equals("课程笔记.txt")) {
						String content = FileUtil.readByChars(f.getPath());
						FileUtil.saveAs(content,newPath+f.getParentFile().getName()+".txt");
					}else {
						continue;
					}
				}
			}
		}else {
			return;
		}
	}
	
	public static void main(String[] args) {
		String rootPath = "/Volumes/Seagate Backup Plus Drive/大数据/BaiduNetdiskDownload/587233 Elasticsearch顶尖高手系列课程-核心知识篇+高手进阶篇all/【中华石杉】Elasticsearch顶尖高手系列课程-核心知识篇/资料";
		String newPath="/Volumes/Seagate Backup Plus Drive/大数据/BaiduNetdiskDownload/EStexts/";
		reName(rootPath,newPath);
	}
}
